package cn.cloudtogo.support.mysql.table;

import cn.cloudtogo.support.mysql.column.Types;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * @author yaolianhua789@gmail.com
 **/
@Data
public class AlterTableTemplate {

    private String name;

    private TableRename tableRename;
    private AddColumn addColumn;
    private DropColumn dropColumn;
    private ModifyColumnDefinition modifyColumnDefinition;
    private ModifyColumnName modifyColumnName;

    public boolean isTableRename() {
        return tableRename != null;
    }

    public boolean isAddColumn() {
        return addColumn != null;
    }

    public boolean isDropColumn() {
        return dropColumn != null;
    }

    public boolean isModifyColumnDefinition() {
        return modifyColumnDefinition != null;
    }

    public boolean isModifyColumnName() {
        return modifyColumnName != null;
    }

    @Data
    public static class TableRename {
        private String newName;
    }

    @Data
    public static class AddColumn {
        private String name;
        private Types types;
        private boolean notNull;
        @JsonProperty("default")
        private String defaultValue;
        private String comment = "";
    }

    @Data
    public static class DropColumn {
        private String name;
    }

    @Data
    public static class ModifyColumnDefinition {
        private String name;
        private Types types;
        private boolean notNull;
        @JsonProperty("default")
        private String defaultValue;
        private String comment = "";
    }

    @Data
    public static class ModifyColumnName {
        private String originColumn;
        private String newColumn;
        private Types types;
        private boolean notNull;
        @JsonProperty("default")
        private String defaultValue;
        private String comment = "";
    }
}
